<?php
namespace app\controller\demo;

use app\services\ai\AiInterface;
use app\facade\Ai;
use app\services\ai\Baidu;
use EasyWeChat\Kernel\Support\File;
use think\facade\Response;

class Artificial extends Application
{
    /**
     * 动态绑定用法
     */
    public function baidu()
    {
        bind(AiInterface::class, new Baidu(config('ai.baidu')));
        $res = app(AiInterface::class)->text2Audio(['txt' => '你好']);
        //dump(File::getStreamExt($res)); //获取资源ext
        /**
         * 直接输出资源
         */
        return Response::data($res)->contentType('audio/mp3');
    }

    /**
     * 环境配置facade用法，要事先配置好config
     * 看app/facade/Ai中的定义
     */
    public function qq()
    {
        return json(Ai::textChat(['question' => '广州买车地方']));
    }
}
